﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class Tbl_DonHang_BUS
    {
        public static Tbl_DonHang_Collection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            return dhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static Tbl_DonHang_Collection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            return dhDAL.Get(cri.Criter, 0, 0, Tbl_DonHang_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static Tbl_DonHang_Entities GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_DonHang_Columns.STT.ToString(), Condition.EQUAL, iD);
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            Tbl_DonHang_Collection dhCollection = dhDAL.Get(cri.Criter, 0, 0, Tbl_DonHang_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (dhCollection.Count > 0)
                return dhCollection[0];
            return null;
        }
        public static Tbl_DonHang_Entities GetByMADH(string iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_DonHang_Columns.MaDH.ToString(), Condition.EQUAL, iD);
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            Tbl_DonHang_Collection dhCollection = dhDAL.Get(cri.Criter, 0, 0, Tbl_DonHang_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (dhCollection.Count > 0)
                return dhCollection[0];
            return null;
        }
        public static int Insert(Tbl_DonHang_Entities dh)
        {
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            return dhDAL.Insert(dh);
        }
        public static void Update(Tbl_DonHang_Entities dh)
        {
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            dhDAL.Update(dh);
        }
        public static void Update_ThanhToanDN(string madh)
        {
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            dhDAL.Update_Thanhtoan(madh);
        }
        public static void Update_DAGIAO(string madh)
        {
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            dhDAL.Update_dagiao(madh);
        }
        public static void Update_NGUOIDUNGTHANHTOAN(string madh)
        {
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            dhDAL.Update_nguoidungdathanhtoan(madh);
        }
        public static void Delete(int id)
        {
            Tbl_DonHang_DAL dhDAL = new Tbl_DonHang_DAL();
            dhDAL.Delete(id);
        }
    }
}
